package com.ztools.common.config.rabbitMq.config;

import com.ztools.common.util.common.enumUnit.RoutingKeyEnum;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import static com.ztools.common.config.rabbitMq.config.ExchangeConfig.DLX_EXCHANGE;

/**
 * @Author: 一口香菜
 * @Date: 2023/3/24  12:39
 * @Version 1.0
 * 队列配置类
 */
@Component
public class QueueConfig {

    /**
     * 订单的消息队列
     */
    public static final String ORDER_QUEUE = "order_queue";

    /**
     * 开卡的消息队列
     */
    public static final String OPEN_CARD_QUEUE = "open_card_queue";

    /**
     * 死信队列
     */
    public static final String DLX_QUEUE = "dlx_queue";


    /**
     * 1.创建订单消息队列的消息队列
     *
     * @return Queue
     */
    @Bean("orderQueue")
    public Queue bootQueue() {
        return QueueBuilder.durable(ORDER_QUEUE)
                .ttl(30 * 1000)
                .deadLetterExchange(DLX_EXCHANGE)
                .deadLetterRoutingKey(RoutingKeyEnum.DLX_KEY.getRoutingKey())
                .maxLength(50)
                .build();
    }

    /**
     * 2.死信队列
     */
    @Bean("dlxQueue")
    public Queue dlxQueue() {
        return QueueBuilder
                .durable(DLX_QUEUE)
                .ttl(24 * 60 * 60 * 1000)
                .build();
    }

    /**
     * 开卡的消息队列
     *
     * @return Queue
     */
    @Bean("openCardQueue")
    public Queue openCardQueue() {
        return QueueBuilder
                .durable(OPEN_CARD_QUEUE)
                .ttl(30 * 1000)
                .deadLetterExchange(DLX_EXCHANGE)
                .deadLetterRoutingKey(RoutingKeyEnum.DLX_KEY.getRoutingKey())
                .maxLength(50)
                .build();
    }
}
